﻿Chenxin.UI.IncomeSummeryPersonalDetail = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/IncomeSummaryPersonalDetail.ashx',
    createSearch: function() {
        this.personalsearch = new Chenxin.UI.IncomeSummeryPersonalSearch({
            scope: this
        });
        return this.personalsearch;
    },
    
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.JsonGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
				}];
            },
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 50,
            height: 400,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            scope: this,
            autoLoad: false,
            id: 'BalanceList',
            modelId: 'UserId',
            title: '个人实收统计明细表',
            scope: this,
            columns: {
				UserCode: { head: '员工编号', width: 120, sortable: true },
                UserName: { head: '员工姓名', width: 100, sortable: true },
                Business: { head: '所在商圈', width: 100, sortable: true },
                DepartName: { head: '所在门店', width: 120, sortable: true },
				ContractDate: { head: '成交日期', width: 120, sortable: true },
				ContractCode: { head: '成交编号', width: 120, sortable: true },
                Income: { head: '个人实收', width: 100, sortable: true },
				PayArchDate: { head: '实收日期', width: 100, sortable: true,
				    renderer: function(val, field, row) {
				        if (val.indexOf('.') >= 0) {
				            return val.substring(0, 4) + '年' + val.substring(5.1) + '月';
				        }
				        else {
				            return '';
				        }
				    }
				},
				BusinessType: { head: '业务类型', width: 100, sortable: true }
            }
        });
    },
    exportAll: function() {
		_this = this;
        paramStr = this.search.getParamJson();
        paramStr.op = 'exportAll';
        Chenxin.Msg.Waiting.show();
        Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
        
        Chenxin.Msg.Waiting.hide();
    },
    initComponent: function() {
		Chenxin.UI.IncomeSummeryPersonalDetail.superclass.initComponent.call(this);
    }
});


Chenxin.UI.IncomeSummeryPersonalWin=Chenxin.extend(Chenxin.UI.Win,{	
	id:'',
	actionUrl:'',
	width:680,
	hasFoot:true,
	height:360,
	content:'<div id="x_details_grid"></div>',
	createBtn:function(){
		return [{
			text:'刷新',
			handler:this.refreshGrid
		},{
			text:'关闭',
			handler:this.hide
		}]	
	},
	refreshGrid:function(){
		this.grid.reload();
	},
	createGrid:function(){
		if(this.grid){
			return;
		}
		this.grid = new Chenxin.UI.ReportGrid({
			autoLoad:false,
			actionUrl:this.actionUrl,
            id: 'x_details_grid',
            renderTo: 'x_details_grid',
            hasCheckBox: false,
            modelId: 'a',
            cellBorder: true,
            scope: this,
			height:311,
			hasTitle:false,
			columns:{
			Business: { head: '商圈', width: 100, sortable: true, captionCol: true },
			PointDepart: { head: '门店', width: 150, sortable: true, inTotal: false },
			ContractCode: { head: '成交编号', width: 150, sortable: true, inTotal: false },
			ContractDate: { head: '成交日期', width: 100, sortable: true, inTotal: false },
			Region: { head: '区域', width: 100, sortable: true, inTotal: false },
			HouseAddress: { head: '房屋地址', width: 200, sortable: true, inTotal: false },
			PointEmp: { head: '业务员', width: 100, sortable: true, inTotal: false },
			DeparterManagerName: { head: '店长', width: 100, sortable: true, inTotal: false },
			MangerName: { head: '高级经理', width: 100, sortable: true, inTotal: false },
			MajordomoName: { head: '总监', width: 100, sortable: true, inTotal: false },
			RealCommisionFinal: { head: '应收佣收', width: 100, sortable: true, inTotal: false },
			CommisionFinal: { head: '折佣', width: 100, sortable: true, inTotal: false },
			ConsultingFinal: { head: '咨询费', width: 100, sortable: true, inTotal: false },
			Results: { head: '业绩', width: 100, sortable: true, inTotal: false },
			Point: { head: '点数', width: 100, sortable: true, inTotal: false },
				ApportionRealCommisionFinal:{head:'分摊应收',width:100,sortable:true},
				ApportionCommisionFinal:{head:'分摊咨询费',width:100,sortable:true},
				ApportionConsultingFinal:{head:'分摊业绩',width:100,sortable:true},
				PayMoney:{head:'实收',width:100,sortable:true},
				ApportionPay:{head:'分摊实收',width:100,sortable:true},
				ContractArchDate: { head: '业绩归属日期', width: 100, sortable: true, inTotal: false },
				BargainCompanyName: { head: '合同归属公司', width: 100, sortable: true, inTotal: false }
			}
		});
	},
	initComponent:function(){
		Chenxin.UI.IncomeSummeryPersonalWin.superclass.initComponent.call(this);
		this.createGrid();
	}
});

/*
* 查询面板
*/
Chenxin.UI.IncomeSummeryPersonalSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
		var _this=this;		
        //人员
        this.comboUserId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtUser',
            txtModelName: 'UserName',
            singleSelect: true,
            name: 'empid'
        });
		
        this.combl = new Chenxin.UI.StructComboList({
            cityAfterSelected: function() {
                _this.comboUserId.reset();
            },
            companyAfterSelected: function() {
                _this.comboUserId.reset();
            },
            businessDistrictAfterSelected: function() {
                _this.comboUserId.reset();
            },
            departsAfterSelected: function(val) {
                _this.comboUserId.reset();
                if (val != '请选择') {
                    _this.comboUserId.loadUser(val, 500);
                }
            }
        });
		
		
		
        //收支情况
        var AchievementType = new Chenxin.UI.Combo({
            containerId: '#AchievementType',
            tbxWidth: 45,
			name:'BusinessType',
            items: comboCommon.AchievementType
        });
		
        var structs = this.combl.comboList;
        structs.push(this.comboUserId);
        structs.push(AchievementType);
        return this.combl.comboList;
    },
    initEvent: function() {
        $(".x_date").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        })
		$('#txtKeyword').defText({
            deftxt: '地址/成交编号/员工编号'
        });

        var curdate = new Date();
        $('#txtActualDate').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));
        $("#txtActualDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
		
        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.IncomeSummeryPersonalDetail();
});